package com.it.utils;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

public class BeanFactory {
    private static Map<String,Object> singerMap=new HashMap<String, Object>();
    static {
        ResourceBundle bundle = ResourceBundle.getBundle("beans");
        Enumeration<String> keys = bundle.getKeys();
        while (keys.hasMoreElements()) {
            String name = keys.nextElement();
            String stringPath = bundle.getString(name);
            Object o=null;
            try {
                Class<?> cls = Class.forName(stringPath);
                o = cls.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            singerMap.put(name,o);

        }
    }

    public static synchronized Object getSingleBean(String beanName) {
        Object o = singerMap.get(beanName);
        if (o == null) {
            singerMap.put(beanName,o);
        }
        return o;
    }
}
